package com.example.hello.service.impl;

import com.example.hello.mapper.UserBorrowCertificateMapper;
import com.example.hello.mapper.UserMapper;
import com.example.hello.pojo.LoginInfo;
import com.example.hello.pojo.User;
import com.example.hello.pojo.UserBorrowCertificate;
import com.example.hello.service.CertificateService;
import com.example.hello.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Autowired
    private UserBorrowCertificateMapper userBorrowCertificateMapper;

    @Override
    public void updateById(Integer userId, LoginInfo loginInfo) {
        userMapper.uodateById(loginInfo);
    }

    @Override
    public User getUserById(Long id) {
        return userMapper.getById(id);
    }

    @Override
    public UserBorrowCertificate getCertificateById(Long id) {
        User user = userMapper.getById(id);
        UserBorrowCertificate certificate = userBorrowCertificateMapper.getById(user.getCertificateId());
        return certificate;
    }
}
